define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'health/project_health_food_nutrition/index' + location.search,
                    add_url: 'health/project_health_food_nutrition/add',
                    edit_url: 'health/project_health_food_nutrition/edit',
                    del_url: 'health/project_health_food_nutrition/del',
                    multi_url: 'health/project_health_food_nutrition/multi',
                    import_url: 'health/project_health_food_nutrition/import',
                    table: 'project_health_food_nutrition',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {field: 'id', title: __('Id')},
                        {field: 'food_id', title: __('Food_id'),visible:false},
                        {field: 'calcium', title: __('Calcium'), operate: 'LIKE'},
                        {field: 'carbohydrates', title: __('Carbohydrates'), operate: 'LIKE'},
                        {field: 'cholesterol', title: __('Cholesterol'), operate: 'LIKE'},
                        {field: 'copper', title: __('Copper'), operate: 'LIKE'},
                        {field: 'dietary_fiber', title: __('Dietary_fiber'), operate: 'LIKE'},
                        {field: 'energy', title: __('Energy'), operate: 'LIKE'},
                        {field: 'fat', title: __('Fat'), operate: 'LIKE'},
                        {field: 'iron', title: __('Iron'), operate: 'LIKE'},
                        {field: 'magnesium', title: __('Magnesium'), operate: 'LIKE'},
                        {field: 'manganese', title: __('Manganese'), operate: 'LIKE'},
                        {field: 'phosphorus', title: __('Phosphorus'), operate: 'LIKE'},
                        {field: 'potassium', title: __('Potassium'), operate: 'LIKE'},
                        {field: 'protein', title: __('Protein'), operate: 'LIKE'},
                        {field: 'saturated', title: __('Saturated'), operate: 'LIKE'},
                        {field: 'sodium', title: __('Sodium'), operate: 'LIKE'},
                        {field: 'sugar', title: __('Sugar'), operate: 'LIKE'},
                        {field: 'trans_fat', title: __('Trans_fat'), operate: 'LIKE'},
                        {field: 'vitamin_c', title: __('Vitamin_c'), operate: 'LIKE'},
                        {field: 'zinc', title: __('Zinc'), operate: 'LIKE'},
                        {field: 'weight', title: __('Weight'), operate:'BETWEEN'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate',visible: false, title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
